package com.movie.modules.jf.controller;

import java.util.HashMap;
import java.util.Map;

import com.movie.modules.jf.service.ActorService;
import com.movie.modules.jf.service.MovieCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.movie.modules.jf.entity.MovieEntity;
import com.movie.modules.jf.service.MovieService;
import com.movie.common.utils.PageUtils;
import com.movie.common.utils.R;



/**
 * 电影表
 *
 * @author kakarot
 * @email 532050892@qq.com
 * @date 2021-08-20 01:31:11
 */
@RestController
@RequestMapping("/sys/movie")
@Api(tags = "后台电影模块")
public class MovieController {
    @Autowired
    private MovieService movieService;

    @Autowired
    private ActorService actorService;

    @Autowired
    private MovieCommentService commentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("分页查询")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = movieService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{moveId}")
    @ApiOperation("详细信息")
    public R info(@PathVariable("moveId") Integer moveId){
        return R.ok().put("data", movieService.getInfoById(moveId));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("添加/修改")
    public R update(@RequestBody MovieEntity movie){
		movieService.update(movie);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{movieId}")
    @ApiOperation("删除信息")
    public R delete(@PathVariable("movieId") Integer moveId){
		movieService.delete(moveId);
        return R.ok();
    }

    @PostMapping("/status")
    @ApiOperation("更改电影状态")
    public R status(@RequestBody MovieEntity movie){
        movieService.updateById(movie);
        return R.ok();
    }

    @GetMapping("/actor/list/{movieId}")
    @ApiOperation("指定电影的演员列表")
    public R actorList(@PathVariable("movieId") Integer moveId){
        Map<String,Object> map=new HashMap<>();
        map.put("list",actorService.getByMovieId(moveId));
        return R.ok().put("data",map);
    }

    @GetMapping("/comment/list/{movieId}")
    @ApiOperation("指定电影的评论列表")
    public R commentList(@PathVariable("movieId") Integer moveId,@RequestParam Map<String,Object> params){
        return R.ok().put("data",commentService.getCommentByMovieId(params,moveId));
    }
}
